home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 2
/
Atari Mega Archive CD - Volume 2.iso
/
minix
/
up1510b.tgz
/
up1510b
/
src
/
lib
/
posix
/
sleep.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-19
|
982b
|
52 lines
/* sleep(3)
*
* Sleep(n) pauses for 'n' seconds by scheduling an alarm interrupt.
*
* Changed to conform with POSIX Terrence W. Holm Oct. 1988
*/
#include <lib.h>
#include <signal.h>
#include <unistd.h>
PRIVATE void _alfun()
{ /* Used with sleep() below */
}
unsigned sleep(secs)
unsigned secs;
{
unsigned current_secs;
unsigned remaining_secs;
void (*old_signal) ();
if (secs == 0) return(0);
current_secs = alarm(0); /* Is there currently an alarm? */
if (current_secs == 0 || current_secs > secs) {
old_signal = signal(SIGALRM, _alfun);
alarm(secs);
pause();
remaining_secs = alarm(0);
signal(SIGALRM, old_signal);
if (current_secs > secs)
alarm(current_secs - (secs - remaining_secs));
return(remaining_secs);
}
/* Current_secs <= secs, ie. alarm should occur before secs */
alarm(current_secs);
pause();
remaining_secs = alarm(0);
alarm(remaining_secs);
return(secs - (current_secs - remaining_secs));
}